import sys

kol = 0
sec = 10

name = ""

def changed(event):
    global kol

    kol = kol + 1

def calculate():
    global kol
    global sec

    fps = kol / sec

    fl = open("report", "w")
    lines = fl.readlines()
    fl.close

    string = "%s: %dfps" % (name, fps)
    lines.append(string)
    
    fl = open("report", "r")
    fl.writelines(lines)
    fl.close()
    

if __name__ == '__main__':
    if len(sys.argv) == 6:
        args = sys.argv
        x = int(args[1])
        y = int(args[2])
        w = int(args[3])
        h = int(args[4])

        name = args[5]

        reg = Region(x, y, w, h)
        with reg as r:
            onChange(10, changed)
            observe(background = True)

        wait(sec)
        r.stopObserver()
        calculate()
    else:
        print("Error....")